package net.jgrm.order;

import lombok.extern.slf4j.Slf4j;
import net.jgrm.idgenerator.service.IdGenerator;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.PostConstruct;
import java.util.Arrays;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "net.jgrm")
@ComponentScan(basePackages = {"net.jgrm"})
@MapperScan("net.jgrm.order.mapper")
@Slf4j
public class OrderServiceApplication {

    @Autowired
    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(OrderServiceApplication.class, args);
    }

    @PostConstruct
    public void checkBeans() {
        String[] beanNames = applicationContext.getBeanNamesForType(IdGenerator.class);
        log.info("加载的IdGenerator Bean: {}", Arrays.toString(beanNames));

        try {
            IdGenerator idGenerator = applicationContext.getBean(IdGenerator.class);
            log.info("当前使用的IdGenerator实现: {}", idGenerator.getClass().getName());
        } catch (Exception e) {
            log.error("IdGenerator Bean未找到: {}", e.getMessage());
        }
    }
}
